//
// Created by Administrator on 2021/11/9.
// May Saint Diana bless you!
//
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <string>

using namespace std;
class Solution {
public:
    string kthDistinct(vector<string>& arr, int k) {
        // 第一次遍历，统计每个字符串出现的次数
        // 第二次遍历，找到第k个独一无二的
        unordered_map<string,int>um;
        for(const string &x:arr){
            if (!um.count(x)){
                um[x] = 0;
            }
            ++um[x];
        }
        int counter  = 0;
        for(const string &x:arr){
            if (um[x] ==1 ){
                ++counter;
                if (counter == k)
                    return x;
            }
        }
        return "";
    }
};
int main() {
    vector<string>arr{"d","b","c","b","c","a"};
    Solution solution;
    cout << solution.kthDistinct(arr,2);
    return 0;
}
